package com.longe.netty.decoderAndEncoder;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * 自定义的编码器, 用于 long 转 byte
 */
public class MyLongToByteEncoder extends MessageToByteEncoder<Long> {
    //编码方法
    @Override
    protected void encode(ChannelHandlerContext ctx, Long msg, ByteBuf out) {

        System.err.println("MyMessageEncoder encode 被调用");
        System.err.println("msg = " + msg);
        out.writeLong(msg);
    }
}
